package com.letou.ls.ui;

import com.letou.ls.R;
import com.letou.ls.uitl.AppSettingPreferencesUtils;
import com.letou.ls.uitl.Constant;
import com.letou.ls.uitl.CorlorSettingPreferencesUtils;
import com.letou.ls.uitl.DialogUtils;
import com.letou.ls.uitl.PreferencesUtils;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;

/**
 * 恢复设置
 *
 * @author
 *
 */
public class RecoverActivity extends Activity {
    private int currentOrientation;
    private TextView bg_recover_setting;
    private TextView bg_exit_logon;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        currentOrientation =
                getIntent().getIntExtra("orientation", Configuration.ORIENTATION_LANDSCAPE);
        if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            setContentView(R.layout.activity_recover_setting_landscape);
        } else {
            setContentView(R.layout.activity_recover_setting_portrait);
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }

        bg_recover_setting = (TextView) findViewById(R.id.bg_recover_setting);
        bg_exit_logon = (TextView) findViewById(R.id.bg_exit_logon);


        bg_recover_setting.setOnClickListener(new OnClickListener() {
            
            @Override
            public void onClick(View v) {
                DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
                    
                    @Override
                    public void onClick(DialogInterface arg0, int arg1) {
                        // TODO Auto-generated method stub
                        AppSettingPreferencesUtils.clear(getApplicationContext());
                        CorlorSettingPreferencesUtils.clear(getApplicationContext());
                        arg0.dismiss();
                        // android.os.Process.killProcess(android.os.Process.myPid());
                        // // 获取PID
                        // System.exit(0); // 常规java、c#的标准退出法，返回值为0代表正常退出
                        Toast.makeText(getApplicationContext(), "清除设置成功!", Toast.LENGTH_SHORT)
                                .show();
                        finish();
                    }
                };

                DialogUtils.showDialog(RecoverActivity.this, "提示", "您确定要恢复默认设置吗?", listener);

            }
        });

        bg_exit_logon.setOnClickListener(new OnClickListener() {
            
            @Override
            public void onClick(View v) {
                DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
                    
                    @Override
                    public void onClick(DialogInterface arg0, int arg1) {
                        // TODO Auto-generated method stub
                        PreferencesUtils.clear(RecoverActivity.this);
                        arg0.dismiss();
                        // android.os.Process.killProcess(android.os.Process.myPid());
                        // // 获取PID
                        // System.exit(0); // 常规java、c#的标准退出法，返回值为0代表正常退出

                        Intent intent = new Intent();
                        intent.putExtra(Constant.PRE_TAG_CURRENT_LTTERY_CODE, "111");
                        setResult(RESULT_OK, intent);
                        finish();
                    }
                };

                DialogUtils.showDialog(RecoverActivity.this, "提示", "您确定要清除登录信息等全部数据吗?", listener);

            }
        });
    }
}
